Repository navigation
[Feature] Support custom labels for operator Deployment and pod - #791
Conversation
Signed-off-by: Tiansu Yu <tiansu.yu@sumup.com>
|
Tick the box to add this pull request to the merge queue (same as
|
There was a problem hiding this comment.
Pull request overview
Adds configurable custom labels to the StarRocks operator Helm chart so users can attach organizational metadata to the operator Deployment and its pods without modifying chart templates or destabilizing the Deployment selector.
Changes:
- Introduces
starrocksOperator.labels(and regenerated parent values) with default{}. - Renders the custom labels onto the operator Deployment
metadata.labelsand pod-templatemetadata.labels. - Keeps
spec.selectorunchanged to avoid immutable-selector churn when labels change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| helm-charts/charts/kube-starrocks/values.yaml | Regenerated parent chart values to expose operator label configuration. |
| helm-charts/charts/kube-starrocks/charts/operator/values.yaml | Adds starrocksOperator.labels default to the operator chart values. |
| helm-charts/charts/kube-starrocks/charts/operator/templates/deployment.yaml | Applies custom labels to Deployment and pod-template metadata. |
Suppressed comments (1)
helm-charts/charts/kube-starrocks/charts/operator/templates/deployment.yaml:33
starrocksOperator.labelscan currently override reserved pod-template labels likeapp(used by the Deployment selector) andversion(used by the chart). If a user sets these keys, the rendered YAML will contain duplicates and can produce an invalid Deployment due to selector/template mismatch. It’s safer to reject configurations that set reserved keys.
app: {{ template "operator.name" . }}-operator
version: {{ $.Chart.Version }}
{{- with .Values.starrocksOperator.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Tiansu Yu <tiansu.yu@sumup.com>
877aee3 to
9fd5283
Compare
|
@kevincai I have fixed a bug spotted by Copilot, do you think you can approve this and we get this merged? |
yandongxiao
left a comment
There was a problem hiding this comment.
Thanks for this. The core design decision is the right one, and it holds up under testing: I ran the chart on a kind cluster and confirmed that custom labels land on the Deployment and the pod template, spec.selector stays untouched, and a helm upgrade that adds — or later removes — labels on an existing release is a clean in-place update, with no immutable-selector failure and the original ReplicaSet reused once the labels are removed again. Default rendering is byte-identical to main.
Two things I ran into while testing, one of which I'd like to see fixed before merge.
1. Non-string label values render an invalid manifest
toYaml emits each value with its YAML type, so any label set without --set-string renders as a scalar the API server cannot decode:
$ helm template ... --set starrocksOperator.labels.rev=123
labels:
app: kube-starrocks-operator
rev: 123 # wanted "123"$ helm upgrade ... --set starrocksOperator.labels.rev=123
Error: UPGRADE FAILED: unable to decode "": json: cannot unmarshal number into Go struct field ObjectMeta.metadata.labels of type stringBooleans behave the same way (prod: true). --set-string works around it, but the error names neither a file nor a values key, so it is hard to trace back to starrocksOperator.labels. Revision numbers, ticket ids and cost-center codes are exactly the kind of values people put in labels, so I think it's worth quoting them in the chart:
{{- range $k, $v := $operatorLabels }}
{{ $k }}: {{ $v | quote }}
{{- end }}and the same at nindent 8's indentation for the pod template. I tried this on your branch: default rendering stays byte-identical, rev=123 / prod=true then render as "123" / "true", and the result applies cleanly.
2. app.kubernetes.io/managed-by silently diverges between Deployment and pod (nit)
Helm sets app.kubernetes.io/managed-by: Helm on release resources itself, so a user-supplied value for that key survives on the pod template but is overwritten on the Deployment:
$ helm upgrade ... --set 'starrocksOperator.labels.app\.kubernetes\.io/managed-by=my-gitops'
deploy.metadata.labels[managed-by] : Helm
pod-template.labels[managed-by] : my-gitopsHarmless in itself, but it makes ownership queries inconsistent between the Deployment and its pods. Adding the key to the reserved list alongside app / version would turn a silent surprise into an explicit error. Entirely your call — feel free to treat this as a nit.
One more thing worth a line in the PR description: because the labels also go on the pod template, setting or changing them rolls the operator pod once. That is expected and does not touch FE/BE/CN, but it's good for users to know up front.
Render numeric and boolean custom label values as strings on the operator Deployment and pod template. Reject unsupported value shapes, quote keys to preserve YAML structure, and reserve the Helm ownership label. Signed-off-by: Tiansu Yu <tiansu.yu@sumup.com>
|
@yandongxiao Thanks for the detailed review, I have addressed the concerns you have mentioned. For 2rd point, I have rejected this particular label from acceptable key-value pairs, should be managed by deployment controller any way. |
Description
Add an optional
starrocksOperator.labelsvalue to the operator Helm chart and render it on the operator Deployment and pod template.Custom labels are intentionally not added to
spec.selector. This keeps the selector stable and allows organizational labels to change without requiring the Deployment to be recreated.The parent
kube-starrocksvalues file has been regenerated withscripts/create-parent-chart-values.sh.Related Issue(s)
Closes #790
Validation
helm lint helm-charts/charts/kube-starrocks/charts/operatorhelm lint helm-charts/charts/kube-starrocksspec.selector.Checklist
Operator code was not changed, so code generation, CRD generation, and Go unit tests are not applicable.
For the Helm chart:
values.yaml.scripts/create-parent-chart-values.shto regenerate the parentkube-starrocksvalues.